<template>
  <view class="trust-card" :class="cardClasses" :data-trust="trustLevel">
    <!-- 卡牌头部 -->
    <view class="card-header">
      <view class="card-icon">{{ cardData.icon }}</view>
      <view class="card-title">{{ cardData.name }}</view>
      <view class="trust-badge" :class="trustLevel">
        <text class="badge-text">{{ getTrustLevelText() }}</text>
      </view>
    </view>
    
    <!-- 信任进度条 -->
    <view class="trust-progress-container">
      <view class="progress-label">
        <text class="label-text">信任值</text>
        <text class="value-text">{{ trustValue }}/100</text>
      </view>
      <view class="progress-bar-wrapper">
        <progress 
          class="trust-progress-bar"
          :value="trustValue" 
          max="100"
          :class="trustLevel"
        />
        <view class="progress-fill" :style="{ width: trustValue + '%' }"></view>
      </view>
    </view>
    
    <!-- 卡牌内容 -->
    <view class="card-content">
      <text class="card-description">{{ cardData.description }}</text>
      
      <!-- 信任效果 -->
      <view class="trust-effects" v-if="trustEffects.length > 0">
        <view 
          class="effect-item" 
          v-for="effect in trustEffects" 
          :key="effect.id"
          :class="{ active: effect.active }"
        >
          <text class="effect-icon">{{ effect.icon }}</text>
          <text class="effect-text">{{ effect.name }}</text>
        </view>
      </view>
    </view>
    
    <!-- 卡牌操作 -->
    <view class="card-actions">
      <button 
        class="action-btn primary" 
        @click="handleTrustAction"
        :disabled="!canPerformAction"
      >
        <text class="btn-text">{{ getActionText() }}</text>
      </button>
      
      <button 
        class="action-btn secondary" 
        @click="showCardDetails"
        v-if="showDetails"
      >
        <text class="btn-text">详情</text>
      </button>
    </view>
    
    <!-- 信任状态指示器 -->
    <view class="trust-indicators">
      <view 
        class="indicator" 
        v-for="indicator in trustIndicators" 
        :key="indicator.type"
        :class="indicator.status"
        :title="indicator.tooltip"
      >
        <text class="indicator-icon">{{ indicator.icon }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'TrustCard',
  props: {
    cardData: {
      type: Object,
      required: true,
      default: () => ({
        id: '',
        name: '',
        icon: '',
        description: '',
        type: 'neutral'
      })
    },
    trustValue: {
      type: Number,
      default: 50
    },
    showDetails: {
      type: Boolean,
      default: true
    }
  },
  
  computed: {
    trustLevel() {
      if (this.trustValue >= 80) return 'high'
      if (this.trustValue >= 50) return 'medium'
      if (this.trustValue >= 20) return 'low'
      return 'broken'
    },
    
    cardClasses() {
      return [
        'trust-card',
        `trust-${this.trustLevel}`,
        `card-${this.cardData.type}`
      ]
    },
    
    trustEffects() {
      const effects = []
      
      if (this.trustValue >= 80) {
        effects.push({
          id: 'blessing',
          icon: '✨',
          name: '信任祝福',
          active: true
        })
      }
      
      if (this.trustValue >= 60) {
        effects.push({
          id: 'cooperation',
          icon: '🤝',
          name: '协作加成',
          active: true
        })
      }
      
      if (this.trustValue <= 20) {
        effects.push({
          id: 'suspicion',
          icon: '⚠️',
          name: '怀疑状态',
          active: true
        })
      }
      
      return effects
    },
    
    trustIndicators() {
      return [
        {
          type: 'cooperation',
          icon: '🤝',
          status: this.trustValue >= 60 ? 'active' : 'inactive',
          tooltip: '协作能力'
        },
        {
          type: 'loyalty',
          icon: '💎',
          status: this.trustValue >= 80 ? 'active' : 'inactive',
          tooltip: '忠诚度'
        },
        {
          type: 'stability',
          icon: '⚖️',
          status: this.trustValue >= 40 ? 'active' : 'inactive',
          tooltip: '稳定性'
        }
      ]
    },
    
    canPerformAction() {
      return this.trustValue > 0
    }
  },
  
  methods: {
    getTrustLevelText() {
      const levels = {
        high: '高度信任',
        medium: '一般信任',
        low: '低度信任',
        broken: '信任破裂'
      }
      return levels[this.trustLevel] || '未知'
    },
    
    getActionText() {
      if (this.trustValue >= 80) return '深度合作'
      if (this.trustValue >= 50) return '建立合作'
      if (this.trustValue >= 20) return '谨慎合作'
      return '修复信任'
    },
    
    handleTrustAction() {
      this.$emit('trust-action', {
        cardId: this.cardData.id,
        action: 'cooperation',
        trustValue: this.trustValue
      })
    },
    
    showCardDetails() {
      this.$emit('show-details', {
        cardId: this.cardData.id,
        cardData: this.cardData,
        trustValue: this.trustValue
      })
    }
  }
}
</script>

<style scoped>
.trust-card {
  background: white;
  border-radius: 20rpx;
  padding: 24rpx;
  margin: 16rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
}

/* 信任状态样式 */
.trust-card.trust-high {
  border: 3rpx solid #4caf50;
  background: linear-gradient(135deg, #f8fff9 0%, #e8f5e8 100%);
}

.trust-card.trust-medium {
  border: 3rpx solid #ff9800;
  background: linear-gradient(135deg, #fff8f0 0%, #ffe6cc 100%);
}

.trust-card.trust-low {
  border: 3rpx solid #ff5722;
  background: linear-gradient(135deg, #fff5f5 0%, #ffe6e6 100%);
}

.trust-card.trust-broken {
  border: 3rpx solid #f44336;
  background: linear-gradient(135deg, #fafafa 0%, #e0e0e0 100%);
  filter: grayscale(0.3);
}

/* 卡牌头部 */
.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  position: relative;
}

.card-icon {
  font-size: 40rpx;
  margin-right: 16rpx;
}

.card-title {
  flex: 1;
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
}

.trust-badge {
  padding: 6rpx 12rpx;
  border-radius: 12rpx;
  font-size: 20rpx;
  font-weight: bold;
}

.trust-badge.high {
  background: #4caf50;
  color: white;
}

.trust-badge.medium {
  background: #ff9800;
  color: white;
}

.trust-badge.low {
  background: #ff5722;
  color: white;
}

.trust-badge.broken {
  background: #f44336;
  color: white;
}

/* 信任进度条 */
.trust-progress-container {
  margin-bottom: 20rpx;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8rpx;
}

.label-text {
  font-size: 24rpx;
  color: #666;
  font-weight: bold;
}

.value-text {
  font-size: 24rpx;
  color: #333;
  font-weight: bold;
}

.progress-bar-wrapper {
  position: relative;
  height: 12rpx;
  background: #e0e0e0;
  border-radius: 6rpx;
  overflow: hidden;
}

/* 隐藏默认进度条样式 */
.trust-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 1;
}

/* 自定义进度条填充 */
.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 6rpx;
  transition: width 0.5s ease;
  z-index: 2;
}

.trust-high .progress-fill {
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  box-shadow: 0 0 8rpx rgba(76, 175, 80, 0.3);
}

.trust-medium .progress-fill {
  background: linear-gradient(90deg, #ff9800, #ffc107);
  box-shadow: 0 0 8rpx rgba(255, 152, 0, 0.3);
}

.trust-low .progress-fill {
  background: linear-gradient(90deg, #ff5722, #ff7043);
  box-shadow: 0 0 8rpx rgba(255, 87, 34, 0.3);
}

.trust-broken .progress-fill {
  background: linear-gradient(90deg, #f44336, #e57373);
  box-shadow: 0 0 8rpx rgba(244, 67, 54, 0.3);
}

/* 卡牌内容 */
.card-content {
  margin-bottom: 20rpx;
}

.card-description {
  font-size: 24rpx;
  color: #666;
  line-height: 1.4;
  display: block;
  margin-bottom: 16rpx;
}

.trust-effects {
  display: flex;
  flex-wrap: wrap;
  gap: 8rpx;
}

.effect-item {
  display: flex;
  align-items: center;
  padding: 6rpx 12rpx;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8rpx;
  font-size: 20rpx;
  opacity: 0.6;
  transition: all 0.3s ease;
}

.effect-item.active {
  background: rgba(76, 175, 80, 0.1);
  opacity: 1;
  color: #4caf50;
  font-weight: bold;
}

.effect-icon {
  margin-right: 4rpx;
  font-size: 18rpx;
}

.effect-text {
  font-size: 18rpx;
}

/* 卡牌操作 */
.card-actions {
  display: flex;
  gap: 12rpx;
  margin-bottom: 16rpx;
}

.action-btn {
  flex: 1;
  padding: 12rpx 20rpx;
  border: none;
  border-radius: 12rpx;
  font-size: 24rpx;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn.primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 4rpx 12rpx rgba(102, 126, 234, 0.3);
}

.action-btn.primary:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 6rpx 16rpx rgba(102, 126, 234, 0.4);
}

.action-btn.primary:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.action-btn.secondary {
  background: #f0f0f0;
  color: #666;
  border: 2rpx solid #e0e0e0;
}

.action-btn.secondary:hover {
  background: #e0e0e0;
}

/* 信任状态指示器 */
.trust-indicators {
  position: absolute;
  top: 16rpx;
  right: 16rpx;
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.indicator {
  width: 24rpx;
  height: 24rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16rpx;
  transition: all 0.3s ease;
}

.indicator.active {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
  transform: scale(1.1);
}

.indicator.inactive {
  background: rgba(0, 0, 0, 0.1);
  color: #999;
  opacity: 0.5;
}

.indicator-icon {
  font-size: 14rpx;
}

/* 响应式设计 */
@media (max-width: 768rpx) {
  .trust-card {
    margin: 12rpx;
    padding: 20rpx;
  }
  
  .card-title {
    font-size: 26rpx;
  }
  
  .card-description {
    font-size: 22rpx;
  }
  
  .action-btn {
    padding: 10rpx 16rpx;
    font-size: 22rpx;
  }
}
</style>

